import React, { useState, useRef } from 'react';
import ReactDOM from 'react-dom';
import { Card, Switch, Button, Modal, message, Popconfirm } from 'antd';
import AutoTable from '@/components/AutoTable';
import InitForm from '@/components/InitForm';
import { deletestore, role, store } from '@/services/basic';
import { connect, Link } from 'umi';
import { Icon } from '@ant-design/compatible';
import routes from '../../../../config/routes';
// type 类型有 table treeselect upload inputnumber datepicker daterange radio select textarea autoinput editor password input

let defaultFields = {
  name: {
    value: null,
    type: 'input',
    title: '门店名称',
    name: ['name'],
    required: true,
  },
  address: {
    value: null,
    type: 'textarea',
    title: '地址',
    name: ['address'],
    required: false,
    col: { span: 24 }, //栅格布局 默认 12
  },
};

function Menu(props) {
  const [vs, cvs] = useState(false), //表单显/隐
    [fields, cf] = useState(defaultFields),
    [iftype, ciftype] = useState({});

  let actionRef = useRef(),
    ChildRef = null;
  function reload() {
    actionRef?.current?.reload();
    ChildRef?.onRefresh();
  }
  const columns = [
    {
      title: '菜单名称',
      dataIndex: 'name',
      key: 'name',
      render: (dom, record) => {
        return record.routes ? (
          <span>{record.name}</span>
        ) : (
          <Link to={record.path}>{record.name}</Link>
        );
      },
    },
    {
      title: '菜单图标',
      dataIndex: 'icon',
      key: 'icon',
      search: false,
      render: (dom, record) => {
        return <Icon type={record.icon} />;
      },
    },
  ];

  return (
    <AutoTable
      pagetitle={props.route.name}
      columns={columns}
      actionRef={actionRef}
      onRef={(node) => (ChildRef = node)}
      expandable={{
        childrenColumnName: 'routes',
      }}
      rowKey="path"
      dataSource={routes[0].routes[2].routes[0].routes.filter((it) => it.name)}
      only={'table'}
      pageSize={100}
    />
  );
}

export default connect(({ basic, loading }) => ({
  basic,
  loading,
}))(Menu);
